<template>
	<view class="study-detail">
		<view v-if="!showLoading">
			<view class="banner" v-if="!showLoading">
				<u-swiper :list="info.mediaList" height="400rpx"></u-swiper>
			</view>
			<view class="info" v-if="!showLoading">
				<view class="title">
					{{info.name}}
				</view>
				<!-- <view class="info-item">
					活动周期：3天
				</view> -->
				<view class="info-item">
					活动时间：{{info.carryStartDate}}～{{info.carryEndDate}}
				</view>
				<view class="info-item">
					联系方式：{{info.tel}}
				</view>
				<view class="info-item">
					联系地址：{{info.address}}
				</view>
				<view class="info-item">
					报名费用：{{info.cost}}元/人
				</view>
			</view>
			<view class="intro">
				<view class="intro-title">
					研学简介
				</view>
				<view class="intro-content" v-if="!showLoading">
					{{info.content}}
				</view>
			</view>
			<view class="comment" v-if="commentList.length">
				<CommentBox :commentList="commentList" :eventId="info.id"></CommentBox>
			</view>
			
			<view class="merch" v-if="merchList.length">
				<MerchBox :merchList="merchList"></MerchBox>
			</view>
		</view>
		
		<view v-else>
			<u-skeleton rows="0" titleWidth="100%" titleHeight="200"></u-skeleton>
			<view class="info">
				<u-skeleton rows="3" titleWidth="40%" rowsWidth="80%"></u-skeleton>
			</view>
			<view class="intro">
				<view class="intro-title">
					研学简介
				</view>
				<u-skeleton rows="3" titleWidth="100%" rowsWidth="100%"></u-skeleton>
			</view>
		</view>

		<view class="footer" v-if="!showLoading">
			<view class="btn" @click="sign">
				立即报名
			</view>
		</view>
	</view>
</template>

<script>
	import CommentBox from '@/components/CommentBox.vue';
	import MerchBox from '@/components/MerchBox.vue';
	
	export default {
		components: {
			CommentBox,
			MerchBox,
		},
		data() {
			return {
				id: '',
				showLoading: true,
				info: {},
				commentList: [],
				merchList: [],
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.getInfo(this.id);
			this.getCommentList(this.id);
			this.getMerchList(this.id);
		},
		onPullDownRefresh() {
			this.getInfo(this.id);
			this.getCommentList(this.id);
			this.getMerchList(this.id);
			uni.stopPullDownRefresh();
		},
		methods: {
			async getInfo(id) {
				const res = await this.$api('/study/mobile/event/info', 'get', {
					id
				});
				this.showLoading = false;
				this.info = res.data;
			},
			async getCommentList(eventId) {
				const res = await this.$api('/study/mobile/comment/page', 'get', {
					page: 1,
					limit: 10,
					eventId
				});
				this.commentList = res.data.list;
			},
			
			async getMerchList(eventId) {
				const res = await this.$api('/study/mobile/merch/page', 'get', {
					page: 1,
					limit: 10,
					eventId
				});
				this.merchList = res.data.list;
			},
			sign() {
				uni.navigateTo({
					url: `/pages/study/sign-up?eventId=${this.info.id}`,
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	.study-detail {
		padding-bottom: 150rpx;
		.banner {
			width: 100%;
			height: 400rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.info {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.title {
				padding: 20rpx 0;
				color: #74BB2A;
			}

			.info-item {
				padding: 10rpx 0;
				font-size: 28rpx;
				color: #666;

				image {
					width: 24rpx;
					height: 24rpx;
				}
			}
		}

		.intro {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.intro-title {
				padding: 20rpx 0;
				color: #74BB2A;
			}

			.intro-content {
				font-size: 28rpx;
				color: #999;
			}
		}

		.comment {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
		}
		
		.merch {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
		}
		
		.footer {
			position: fixed;
			left: 0;
			bottom: 0;
			right: 0;

			.btn {
				width: 100%;
				height: 120rpx;
				line-height: 120rpx;
				background-color: #D7A768;
				text-align: center;
				color: #fff;
			}
		}
	}
</style>